import lodash from 'lodash';
export const strUtils = {
    isEmpty(str: string | null): boolean {
        return str === null || str.length === 0
    },

    isNotEmpty(str: string | null): boolean {
        return !this.isEmpty(str)
    },

    isNull(str: string | null): boolean {
        return str === null
    },

    isNotNull(str: string | null): boolean {
        return !this.isNull(str)
    },

    isString(str: any) {
        return typeof str === "string";
    },

    equals(str1: string, str2: string): boolean {
        return str1 === str2;
    },

    reverse(str) {
        let strArray = str.split('');
        return lodash.toString(lodash.reverse(strArray)).replace(/,/g, '');
    },

    strAscSum(str) {
        let sum = 0;
        let strArray = str.split('');
        strArray.forEach(c => {
            sum += c.charCodeAt();
        });
        return sum;
    },

    startWith(str: string, char: string): boolean {
        return lodash.startsWith(str, char);
    },

    replace(str: string, src: string, target: string): string {
        return lodash.replace(str, src, target);
    },

    removePrefix(str: string, char: string): string {
        return lodash.replace(str, char, '');
    },

    removeAll(str: string, char: string): string {
        return lodash.replace(str, char, '');
    },
}